<?php
require_once("scripts/constraint.php");
require_once("scripts/EKUser.php");

$valid = false;

if(isset($_POST["userid"]))
{
	if(EKUser::validate($_POST["userid"], $_POST["password"]))
	{
		$id =  $_POST["userid"];
		$currentUser = new EKUser($id);
		session_start();//should put to the initial part
		$_SESSION["userid"] = $id;
		$_SESSION["username"] = $currentUser->getName();
		$_SESSION["userType"] = $currentUser->getType();
		$valid = true;
	}
	
}
?>
<html>
<head>
<title><?=SITENAME?> Log in</title>
</head>
<body>
<script language="javascript">
<?php
if(!$valid)
{
	echo "alert(\"Invalid userid or password!\");";
}
?>
history.go(-1);
</script>
</body>
</html>
